package com.nhtrinh.game;

import com.nhtrinh.lib.CustomFont;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.TextView;

public class MainActivity extends Activity {

	TextView tv1;
	TextView tv2;
	TextView tv3;
	
	Context mContext;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		mContext = MainActivity.this;
		
		tv1 = (TextView)findViewById(R.id.activity_main_tv1);
		tv2 = (TextView)findViewById(R.id.activity_main_tv2);
		tv3 = (TextView)findViewById(R.id.activity_main_tv3);
		
		tv1.setText("");
		tv2.setText("");
		tv3.setText("");
		
		CustomFont mCustomFont = new CustomFont(mContext);
		Typeface tf = mCustomFont.loadCustomFont();
		tv1.setTypeface(tf);
		tv2.setTypeface(tf);
		tv3.setTypeface(tf);
		
		
		startAnimation1();
	}
	
	private void startAnimation1(){
		
		tv1.setText("3");
		Animation fade = AnimationUtils.loadAnimation(mContext, R.anim.fade_zoom_in);
		fade.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {}
			
			@Override
			public void onAnimationRepeat(Animation animation) {}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				tv1.setText("");
				startAnimation2();
				
			}
		});
		
		tv1.startAnimation(fade);
	}
	
	private void startAnimation2(){
		
		tv2.setText("2");
		Animation fade = AnimationUtils.loadAnimation(mContext, R.anim.fade_zoom_in);
		fade.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {}
			
			@Override
			public void onAnimationRepeat(Animation animation) {}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				tv2.setText("");
				startAnimation3();
				
			}
		});
		
		tv2.startAnimation(fade);
	}
	
	private void startAnimation3(){
		
		tv3.setText("1");
		Animation fade = AnimationUtils.loadAnimation(mContext, R.anim.fade_zoom_in);
		fade.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {}
			
			@Override
			public void onAnimationRepeat(Animation animation) {}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				tv3.setText("");
				startActivity(new Intent(mContext, MenuActivity.class));
				
			}
		});
		
		tv3.startAnimation(fade);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	

}
